<?php $this->load->view(TEMPLATE_NAME.'/front/header'); ?>
<?php $this->load->view(TEMPLATE_NAME.'/front/side_left'); ?>
<!--<script type="text/javascript" src="http://www.google.com/jsapi?key=<?php echo GOOGLE_MAPS_API_KEY  ?>"></script>-->
<!--<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo GOOGLE_MAPS_API_KEY  ?>" type="text/javascript"></script>-->
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="<?php echo base_url(); ?>js/nameCapitalization.js"></script>


<script type="text/javascript">
function initialize() {
    geocoder = new google.maps.Geocoder();
        var myLatlng = new google.maps.LatLng($('#sys_lat').val() ,$('#sys_lng').val());
    var myOptions = {
      zoom: 13,
      center: myLatlng,
      mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
   var image = new google.maps.MarkerImage('<?php echo base_url(); ?>image/point/pin_point.png',
      // This marker is 20 pixels wide by 32 pixels tall.
      new google.maps.Size(24, 35),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(0, 32));
  var shadow = new google.maps.MarkerImage('<?php echo base_url(); ?>image/point/pin_point_shadow.png',
      // The shadow image is larger in the horizontal dimension
      // while the position and offset are the same as for the main image.
      new google.maps.Size(49, 35),
      new google.maps.Point(0,0),
      new google.maps.Point(10, 35)); 
    marker = new google.maps.Marker({
        position: myLatlng, 
        map: map,
	draggable: true,
	title:"Incident Location",
	icon: '<?php echo base_url(); ?>image/point/pin_point.png',
	shadow: shadow  
    });   
      $('#sys_latlng').val(myLatlng);
    // Add dragging event listeners.
    google.maps.event.addListener(marker, 'dragend', function() {
      $('#sys_latlng').val(marker.getPosition());
      $('#sys_lat').val(marker.getPosition().lat());
      $('#sys_lng').val(marker.getPosition().lng());
    });


  }
    

  
   function codeAddress() {
      var street_address = document.getElementById("street_address").value;
      var city_address = document.getElementById("city_address").value;
	  var region= $('#region_id :selected').text();
;
	  var address = street_address+', '+city_address+' , '+region;
      if (geocoder) {
	geocoder.geocode( { 'address': address}, function(results, status) {
	  if (status == google.maps.GeocoderStatus.OK) {
	    map.setCenter(results[0].geometry.location);
	    marker.setPosition(results[0].geometry.location);
	    $('#sys_latlng').val(marker.getPosition());
	    $('#sys_lat').val(marker.getPosition().lat());
	    $('#sys_lng').val(marker.getPosition().lng());
	  } else {
	    alert("Geocode was not successful for the following reason: " + status);
	  }
	});
      }
    }
  $(document).ready(function(){
							 		initialize();

	 $('#street_address').change(function(){
	    codeAddress();
    });
    $('#region_id').change(function(){
	    codeAddress();
    });
    $('#city_address').change(function(){
	    codeAddress();
    });
	//  initialize_v3();
    // initialization on onload
    //var map;
    //var marker;
    //initialize();



  });    
   

function testfunction(sentval)
{
	if(sentval == 1)
	{
		document.getElementById('addressdiv').style.display = "none";
        document.getElementById('boxmap').style.display = "none";
	} else {
		document.getElementById('addressdiv').style.display = "block";
        document.getElementById('boxmap').style.display = "block";
		initialize();
	}
}


function checkvalidation()
{
	if(document.getElementById('yeslocation').checked == true)
	{
		var street_address = document.getElementById('street_address').value;
		var city_address = document.getElementById('city_address').value;
		var region_id = document.getElementById('region_id').value;
		
		if(street_address == "")
		{
			document.getElementById('streetaddress').style.display = 'block';
			return false;
		} else {
			document.getElementById('streetaddress').style.display = 'none';
		}
		
		if(city_address == "")
		{
			document.getElementById('cityaddress').style.display = 'block';
			return false;
		} else {
			document.getElementById('cityaddress').style.display = 'none';
		}
		
		if(region_id == "")
		{
			document.getElementById('provinceerr').style.display = 'block';
			return false;
		} else {
			document.getElementById('provinceerr').style.display = 'none';
		}
	}

}

</script>
<div class="page">
<h2>Post News </h2>

<!--<div class="clear"></div>-->
<?php $this->load->view(TEMPLATE_NAME.'/front/news_header'); 
// $insertnewsid = $this->session->userdata('newsid');
//$news_location = $this->News_model->get_all_news($insertnewsid);
if($newscontent[0]['id'] != "") {
	$locationuse = $newscontent[0]['use_location'];
} else {
	$locationuse = '2';
}
//$locationuse =  set_value('location');
if($locationuse == '2')
{
	$selected2 = "selected";
	$selected1 = "";
	$display = "block";
	?>
    <script type="text/javascript" language="javascript">showmap();</script>
    <?php
} else {
	$selected2 = "";
	$selected1 = "selected";
	$display = "none";
	
}
?>
<?php
$notlocation = 'id = "nolocation" onClick="testfunction(this.value)"';
$islocation = 'id = "yeslocation" onClick="testfunction(this.value)"';
$attributes = array('class' => 'posts','onSubmit' => 'return checkvalidation()');
echo form_open('news/news_location',$attributes); 

?>
<!--<div>--><p class="phase"><strong>Location</strong> - <span class="purple">Is this News related to a specific address</span><br />
You can input the addres below to tag it to a specific location, which will make it<!--<Br />-->
more visible and relevant to the people in that area.</p><!--</div>-->
<!--<div class="clear"></div>
<div>-->

<!--<div style="float:left;width:20px">--><div class="radios">
<?php echo form_radio('location','1',$selected1,$notlocation); ?> <!--</div><div style="float:left"><span class="purple">-->
<p class="f13"><strong class="f14 purple">News item is NOT related to specific address</strong><!--</span>--><br />
This news is not related to specific location<!--</div>--></p>
<!--<div class="clear"></div> -->
</div><!-- radios -->
<hr />
<!--<div style="float:left;width:20px">--><div class="radios">
<?php echo form_radio('location','2',$selected2,$islocation); ?> <!--</div><div style="float:left"><span class="purple">-->
<p class="f13"><strong class="f14 purple">News item IS related to specific address</strong><!--</span>--><br />
This news is related to specific location. Input the address below.<!--</div>--></p>
<!--<div class="clear"></div> -->
</div><!-- radios -->
<hr />
<div id="addressdiv" style="display:<?php echo $display ?>">
<div class="formap">
<div id="map_canvas" style="width:328px; margin-bottom:7px; height:280px; float:right"></div><!--<br/>-->
<!--<p>--><p class="grey f13"><strong>Confirm the pin is placed correctly.</strong> 
Once your address is found. You can drag the pin to pinpoint the exact location</p>
<!--<strong class="f16"><a href="#">> Fix incorrect marker location</a></strong>-->
</div><!-- formap -->
<!--<div class="wmap" style="width:250px; padding-left:20px">-->
<div class="wmap wmap2">
<strong>Street Address: <sup>*</sup></strong><br/>
<?php 
$street_address_input = array(
	'id'=>'street_address',
	'name'=>'street_address','onBlur'=>'CapitalizeNames(this)'
	
	);
if($newscontent[0]['street_address'] != "")
{
	$streetval = $newscontent[0]['street_address'];
} else {
	$streetval = set_value('street_address');
}
echo form_input($street_address_input,$streetval);
echo "<div style='background-color: #9F0; color:#000; text-align:center; display:none' id='streetaddress'>Please input street address</div>";
?>

<strong>City/Town: <sup>*</sup></strong><br/>
<?php 

$city_address_input = array(
	'id'=>'city_address',
	'name'=>'city_address','onBlur'=>'CapitalizeNames(this)'
	);
if($newscontent[0]['city'] != "")
{
	$cityvalue = $newscontent[0]['city'];
} else {
	$cityvalue = set_value('city_address');
}
echo form_input($city_address_input,$cityvalue);
echo "<div style='background-color: #9F0; color:#000; text-align:center; display:none' id='cityaddress'>Please input city address</div>";?>
<strong>Province: <sup>*</sup></strong><br/>
<?php
if($newscontent[0]['province'] != "")
{
	$provinceval = $newscontent[0]['province'];
} else {
	$provinceval = set_value('region_id');
}
$CI = get_instance();
$CI->load->model('Location_model');
$CI->load->model('Crime_type_model');
$region_list=$CI->Location_model->get_region_by_country(224);
//echo "<pre><font color='#999999'>";print_r($region_list);echo "</font></pre>";
$crime_type_list =$CI->Crime_type_model->get_complete_crime_type();
 ?>
<select name="region_id" id="region_id">
<option value="">Select Province</option>
<?php if(!empty($region_list)): ?>
<?php foreach($region_list as $key=>$value): ?>
<option value="<?php echo $value['id']?>" <?php echo($provinceval == $value['id'] ? "selected" : "") ?>><?php echo $value['name'] ?></option>
<?php endforeach;?>
<?php endif; ?>
</select>

<?php echo "<div style='background-color: #9F0; color:#000; text-align:center; display:none' id='provinceerr'>Please input city address</div>";?>
<br/>
<hr/>
<?php 
if($newscontent[0]['latitude'] != "" )
{
	$latitude = $newscontent[0]['latitude'];
} else {
	$latitude  = '-26.2';
}

if ($newscontent[0]['longitude'] != "")
{
	$longitude = $newscontent[0]['longitude'];
} else {
	$longitude = '28.03333';
}
?>
<strong>GPS Cordinates: <sup>(optional)</sup></strong><br/>
<!--<strong>--><strong class="same">Latitude:</strong> <?php echo form_input(array('name'=>'latitude','class'=>'w100','id'=>'sys_lat'),$latitude );?><!--<br />-->
<!--<strong>--><strong class="same">Longitude:</strong> <?php echo form_input(array('name'=>'longitude','class'=>'w100','id'=>'sys_lng'),$longitude);?>
 <!--<?php echo form_hidden(array('name'=>'sys_latlng','id'=>'sys_latlng'),'');?>-->
<input type="hidden" name="sys_latlng" id="sys_latlng"/>
<hr/>

</div><!-- wmap -->
<div class="clear"></div>
<!--</div>-->
<!--</div>-->
<!--<div class="clear"></div>-->
<!--<div>--><hr class="mb0" />

<!--<div class="clear"></div>
<div>-->
</div>
<?php echo form_submit('step1sub', 'Submit','class="mb0"'); ?> <!--</div>--><hr /> 
<p class="boxmap black" id="boxmap" style="display:<?php echo $display ?>">
<strong>Please check your address carefully to your post this incident report in the correct area. <!--<<br />-->Mistakes can happen if you address is inputted wrong</strong>
<br/><br/>
<strong>Capitals:</strong> Input address details with capitals e.g 123 <strong>M</strong>ain <strong>S</strong>tree, <strong>B</strong>edfordview.
<br/><br/>
<strong>Street/Road/Avenue:</strong> Sometimes Google maps may have your address saved differently as a Street instead of an Avenue or Road e.g. Dlamini Avenue vs Dlamini Street.
<br/><br/>
<strong>City or Town:</strong> Please input this to narrow down your search
<!--</div>-->
</p>
<?php echo form_close(); ?> 
<!--<div class="clear"></div>-->
    <?php $this->load->view(TEMPLATE_NAME.'/front/footer_menu');?>
</div><!-- page -->

<?php $this->load->view(TEMPLATE_NAME.'/front/side_right');?> 
<?php $this->load->view(TEMPLATE_NAME.'/front/footer');?> 